;;; init-wm.el --- Window manager settings -*- lexical-binding: t -*-
;;; Commentary:

;;; Code:

(use-package shackle
  :ensure t
  :hook (elpaca-after-init . shackle-mode)
  :init
  (setq shackle-rules
        '(("\\*Async Shell.*\\*" :regexp t :select t :ignore t)
          (browse-kill-ring-mode :select t :align t :popup t)
          ("\\*Buffer List\\*"   :regexp t :select t :align t)
          ("*color-rg*"       :select t :align t :other t)
          ("\\*corfu.*\\*"    :regexp t :select t :ignore t)
          (compilation-mode   :select t :size 0.4 :align t :popup t)
          ("*Calendar*"       :select t :size 0.4 :align t :popup t)
          (diff-mode          :align right :popup t)
          (eshell-mode        :select t :align t :popup t)
          ("*fanyi*"          :select t :align t :popup t)
          ("\\*Flymake.*\\*"  :regexp t :select t :align t :popup t)
          ("^\\*Geiser .* REPL\\*" :regexp t :size 0.2 :align below :other t)
          ("\\*gud-.*\\*"     :regexp t :select t :align t :other t)
          (help-mode          :select t :align right :other t)
          (helpful-mode       :select t :align right :other t)
          ("*info*"           :same t)
          ("\\*lsp-bridge-doc.*\\*" :regexp t :select t :size 0.4 :align t :other t :inhibit-window-quit t)
          ("*Messages*"       :align t :select t :popup t)
          (magit-status-mode  :inhibit-window-quit t :same t)
          (magit-log-mode     :inhibit-window-quit t :same t)
          (occur-mode         :select t :popup t)
          ("*Org Agenda*"     :same t)
          ("*quickrun*"       :select t :size 0.3 :align t :popup t)
          ("*vterm*"          :select t :size 0.3 :align t :popup t))))

;; 恢复窗口布局
(use-package winner
  :ensure nil
  :hook (elpaca-after-init . winner-mode)
  :init
  ;; 以下的 buffers 将不通过 winner 恢复
  (setq winner-boring-buffers
        '("*Completions*"
          "*Compile-Log*"
          "*inferior-lisp*"
          "*Fuzzy Completions*"
          "*Apropos*"
          "*Help*"
          "*cvs*"
          "*Buffer List*"
          "*Ibuffer*"
          "*esh command on file*")))

(use-package windresize
  :ensure t
  :commands (windresize-balance-windows
             windresize-up
             windresize-down
             windresize-left
             windresize-right
             windresize-up-fixed
             windresize-down-fixed
             windresize-left-fixed
             windresize-right-fixed)
  :custom
  (windresize-default-increment 3) ; 每次窗口大小变化的步长
  :config
  (setq windresize-increment 3))

(use-package buffer-move
  :ensure t
  :commands (buf-move-up
             buf-move-down
             buf-move-left
             buf-move-right))

;; Manage buffers
(use-package ibuffer
  :ensure nil
  :commands (ibuffer)
  :custom
  (ibuffer-filter-group-name-face '(:inherit (font-lock-string-face bold)))
  :config
  (setq ibuffer-formats
        '((mark modified read-only " "
                (name 40 40 :left :elide)
                " "
                (size 9 -1 :right)
                " "
                (mode 16 16 :left :elide)
                " "
                project-relative-file))))

(use-package ibuffer-projectile
  :ensure t
  :hook (ibuffer . (lambda ()
                     (ibuffer-projectile-set-filter-groups)
                     (unless (eq ibuffer-sorting-mode 'alphabetic)
                       (ibuffer-do-sort-by-alphabetic)))))

(provide 'init-wm)
;;; init-wm.el ends here
